app.service('couponsDetailEditService',['$q','utilService',function($q,utilService){
    var _this_=this;
    _this_.coupons={};

    //查询单个优惠卷
    _this_.findById= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'coupons/'+$scope.id
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    //编辑优惠卷
    _this_.editCoupons=function($scope){
        var coupons=new Object();
        coupons.id=_this_.coupons.id;
        coupons.name=_this_.coupons.name;
        coupons.introduce=_this_.coupons.introduce;

        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"coupons",
            data:coupons,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }



}])